/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.common.data;

import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * 
 * Generic TreeNodeList : list of TreeNodes
 * 
 * @author Laurent GUERIN
 *  
 */
public class TreeNodeList implements Serializable
{
	private static final long serialVersionUID = 1L;
	
	private LinkedList<TreeNode> _list = new LinkedList<TreeNode>();
    
    //----------------------------------------------------------------------------------------
    // Contructor(s)
    //----------------------------------------------------------------------------------------    
    /**
     * Constructs a new TreeNodeList
     */
    public TreeNodeList ()
    {
        super();
    }
    
    //----------------------------------------------------------------------------------------
    // Child nodes management
    //----------------------------------------------------------------------------------------    
    /**
     * Appends a child node
     * @param node
     * @return
     */
    /* package */ boolean add( TreeNode node ) 
    {
        return _list.add(node);
    }

    //-----------------------------------------------------------------------------
    /**
     * Returns an iterator over the elements in this list in proper sequence
     * 
     * @return the iterator
     */
    public Iterator<TreeNode> iterator()
    {
        return _list.iterator();
    }

    //-----------------------------------------------------------------------------
    /**
     * Returns the number of elements in this list.
     * 
     * @return
     */
    public int size()
    {
        return _list.size();
    }

    //-----------------------------------------------------------------------------
    /**
     * Returns 'true' if this list contains no elements
     * 
     * @return
     */
    public boolean isEmpty()
    {
        return _list.isEmpty();
    }

    //-----------------------------------------------------------------------------
    /**
     * Returns the node located at the given index
     * @param index
     * @return the node or null if no node at this index
     */
    public TreeNode get(int index)
    {
        if (_list.isEmpty())
        {
            return null;
        }
        else
        {
            return (TreeNode) _list.get(index);
        }
    }

    //----------------------------------------------------------------------------------------    
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() 
    {
        return "TreeNodeList [" + _list.size() + " node(s)" +"]";
    }
    
}
